<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
</head>
<body>

<div id="view"></div>

<script id="demo" type="text/html">
    <h3>自定义函数：{{ layui.laytpl.fn() }}</h3>
    <h3>自定义函数2：{{ layui.laytpl.fn1('hello') }}</h3>
    <h3>自定义函数2：{{ layui.laytpl.returnFloat('3.100') }}</h3>

    <h3>{{ d.title }}</h3>
</script>


<script src="../layui/layui.js"></script>

<script>
    layui.use('laytpl',function(){

        var laytpl = layui.laytpl;

        laytpl.fn = function(){
            return 'test';
        }


        laytpl.fn1=function (username) {
            return username;
        }


        laytpl.returnFloat = function(value){
            var value=Math.round(parseFloat(value)*100)/100;
            var xsd=value.toString().split(".");
            if(xsd.length==1){
                value=value.toString()+".00";
                return value;
            }
            if(xsd.length>1){
                if(xsd[1].length<2){
                    value=value.toString()+"0";
                }
                return value;
            }
        }


        var data = { //数据
            "title":"Layui常用模块"
            ,"list":[{"modname":"弹层","alias":"layer","site":"layer.layui.com"},{"modname":"表单","alias":"form"}]
        }
        var getTpl = demo.innerHTML
            ,view = document.getElementById('view');
        laytpl(getTpl).render(data, function(html){


            view.innerHTML = html;
        });
    });




</script>
</body>
</html>